/********************************************************************************
 * InvoiceManagementAction.java
 *
 * Created by Jigar Mistry
 * Last modified Date: Jan 1, 2009 2:35:38 PM by Jigar Mistry
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ********************************************************************************/
package com.printeverywhere.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.delegator.UserServiceDelegator;
import com.printeverywhere.dto.AdminDetails;
import com.printeverywhere.dto.AuctionInvoices;
import com.printeverywhere.dto.Transactions;
import com.printeverywhere.dto.User;
import com.printeverywhere.util.SearchCriteria;

public class InvoiceManagementAction extends AdminEngineManagement implements ServletRequestAware {

	/** */
	private static final long serialVersionUID = 1L;

	private HttpServletRequest request;

	private AuctionInvoices auctionInvoices;

	private User user;

	private AdminDetails adminDetails;

	private List<AuctionInvoices> auctionInvoicesList = new ArrayList<AuctionInvoices>();

	private List<Transactions> transactionList = new ArrayList<Transactions>();

	public String viewInvoices() {
		List<Criterion> criterionList = new ArrayList<Criterion>();
		criterionList.add(Restrictions.eq("user", UserServiceDelegator.getUser(Integer.parseInt(request.getParameter("accountDetailid")))));
		this.auctionInvoicesList = (List<AuctionInvoices>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, AuctionInvoices.class);
		return SUCCESS;
	}

	public String viewInvoiceDetails() {
		SearchCriteria searchCriteria = new SearchCriteria();
		searchCriteria.setAttribute("invoice", request.getParameter("invoice"));
		auctionInvoicesList = (List<AuctionInvoices>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, AuctionInvoices.class);

		this.auctionInvoices = (auctionInvoicesList != null && auctionInvoicesList.size() > 0) ? auctionInvoicesList.get(0) : null;
		this.user = UserServiceDelegator.getUser(this.auctionInvoices.getUser().getId());

		List<Criterion> criterionList = new ArrayList<Criterion>();
		criterionList.add(Restrictions.eq("invoice", this.auctionInvoices));
		this.transactionList = (List<Transactions>) CommonFunctionDelegator.getObjectsByCriterion(criterionList, null, null, Transactions.class);
		this.adminDetails = (AdminDetails) CommonFunctionDelegator.getAllfromtable(AdminDetails.class.getName()).get(0);

		return SUCCESS;
	}

	public List<AuctionInvoices> getAuctionInvoicesList() {
		return auctionInvoicesList;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public AuctionInvoices getAuctionInvoices() {
		return auctionInvoices;
	}

	public List<Transactions> getTransactionList() {
		return transactionList;
	}

	public AdminDetails getAdminDetails() {
		return adminDetails;
	}

	public User getUser() {
		return user;
	}
}
